/*
 * Script to manage tool tips
 * 
 * Author: Chris Casola
 */

/*
 * Add an event listener to each of the tool tips on the page
 */
function addToolTipListeners() {
	var tips = document.getElementsByClassName('tip');
	for (var i = 0; i < tips.length; i++) {
		if (!(tips[i].id == 'addChoice' || tips[i].id == 'removeChoice')) {
			tips[i].addEventListener("mouseover", toolTipController, false);
		}
	}
}

/*
 * Controller that is triggered when the user hovers their
 * mouse over a tool tip
 */
function toolTipController(event) {
	var message = toolTips[event.target.id];
	showToolTip(message, event);
}

/*
 * Display a tool tip on the page
 */
function showToolTip(message, event) {
	var toolTip = document.createElement('section');
	toolTip.setAttribute('id', 'toolTip');
	toolTip.innerHTML = "<p>" + message + "</p>";
	toolTip.style.position = "absolute";
	toolTip.style.left = event.target.offsetLeft + "px";
	toolTip.style.top = event.target.offsetTop + "px";
	toolTip.addEventListener('mouseout', removeToolTip, false);
	document.getElementsByTagName('body')[0].appendChild(toolTip);
}

/*
 * Remove all tool tips on the page
 */
function removeToolTip() {
	var toolTip = document.getElementById('toolTip');
	toolTip.parentNode.removeChild(toolTip);
}